package eop.project;
import eop.project.Volcano;
import grails.test.GrailsUnitTestCase;

class VolcanoTest extends GrailsUnitTestCase {
	protected void setUp() {
		super.setUp()
	}
	
	protected void tearDown() {
		super.tearDown()
	}
	// Find volcano details
	void testSomething() {
		mockDomain (Volcano)
		mockDomain(Location)
		mockDomain(Eruption)
		mockDomain (Damage)
		mockDomain (Activity)
		Volcano v=new Volcano(volcanoName:'Sarigan'.toUpperCase(),volcanoType:'Stratovolcano',volcanicRef:'0804-191',status:'Holocene')
		assertNull Volcano.findByVolcanoType("Stratovolcano")
		v.location=new Location(locationName:'Mariana Is-C Pacific',lattitude:16.708,longitude:145.78,elevation:538)
		Eruption e=new Eruption(vei:"",agent:'',startDate:"",endDate:"",eventDate:"2010-05-29")
		e.damage=new Damage(injuries:"21",Houses:"23",numberOfDeaths:"",damages:"")
		Activity a=new Activity(vaac:'Darwin',color:'red')
		e.addToActivities(a).save()
		v.addToEruptions(e).save()
		v.validate()
		v.save()
		
		if(v.hasErrors()){
			v.errors.each{ println "volcano error : $it" }
		}
		else
			println "$v.volcanoName"
		assertFalse v.hasErrors()
		assertNotNull Volcano.findByVolcanoType("Stratovolcano")
		assertNotNull Volcano.findByVolcanoName("SARIGAN")
		assertNotNull Volcano.findByVolcanicRef("0804-191")
		assertNotNull Volcano.findByStatus("Holocene")
		//assertNotNull Volcano.findByEventDate('2010-05-29')
		//assertNotNull Volcano.findByLocationName("Mariana Is-C Pacific")
	}
	/*
	 *   For Unique constraints
	 */
	void testVolcanoName() {
		mockDomain (Volcano)
		Volcano v=new Volcano(volcanoName:'Sarigan',volcanoType:'Stratovolcano',volcanicRef: '0804-191',status:'Holocene')
		v=new Volcano(volcanoName:'Sarigan',volcanoType:'Stratovolcano',volcanicId: '0804-191',status:'Holocene')
		
		v=new Volcano(volcanoName:'Kikai',volcanoType:'Caldera',volcanicId:'',status:'Holocene')
		assertNull Volcano.findByVolcanoType("caldera")		//not saved
	
		v.validate()
		v.save()
		if(v.hasErrors()){
			v.errors.each{ println "volcano error : $it" }
		}
		else
		
			println "$v.volcanoType"
				
		//assertFalse v.hasErrors()		
		assertNotNull Volcano.findByVolcanoType("Caldera")
		}
	
}
